package com.xxworkshop.dtcqcalculator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by brochexu on 10/20/14.
 */
public class HeroItem extends Object {
    public long heroid;
    public long rankid;
    public String heroname;
    public String rankname;
    public List<Long> equipments = new ArrayList<Long>();

    public HeroItem() {
    }

    public HeroItem(String str) throws Exception {
        String[] strs = str.split("\\|");
        if (strs.length == 5) {
            heroid = Long.parseLong(strs[0]);
            rankid = Long.parseLong(strs[1]);
            heroname = strs[2];
            rankname = strs[3];
            String[] ss = strs[4].split("!");
            for (String s : ss) {
                if (!s.equals("")) {
                    equipments.add(Long.parseLong(s));
                }
            }
        } else {
            throw new Exception("not enough lenght");
        }
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(heroid);
        sb.append("|");
        sb.append(rankid);
        sb.append("|");
        sb.append(heroname);
        sb.append("|");
        sb.append(rankname);
        sb.append("|");
        for (Long l : equipments) {
            sb.append(l);
            sb.append("!");
        }
        return sb.toString();
    }
}
